<?php
// ----- >> Extends From Template
class thisPDF extends PDF{
	function Header(){}
	function Footer(){}
}

function terbilang_get_valid($str,$from,$to,$min=1,$max=9){
      $val=false;
      $from=($from<0)?0:$from;
      for ($i=$from;$i<$to;$i++){
        if (((int) $str{$i}>=$min)&&((int) $str{$i}<=$max)) $val=true;
      }
      return $val;
  } 

  function terbilang_get_str($i,$str,$len){
      $numA=array("","satu","dua","tiga","empat","lima","enam","tujuh","delapan","sembilan");
      $numB=array("","se","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      $numC=array("","satu ","dua ","tiga ","empat ","lima ","enam ","tujuh ","delapan ","sembilan ");
      $numD=array(0=>"puluh",1=>"belas",2=>"ratus",4=>"ribu", 7=>"juta", 10=>"milyar", 13=>"triliun");
      $buf="";
      $pos=$len-$i;
      switch($pos){
        case 1:
            if (!terbilang_get_valid($str,$i-1,$i,1,1))
              $buf=$numA[(int) $str{$i}];
          break;
        case 2: case 5: case 8: case 11: case 14:
            if ((int) $str{$i}==1){
              if ((int) $str{$i+1}==0)
                $buf=($numB[(int) $str{$i}]).($numD[0]);
              else
                $buf=($numB[(int) $str{$i+1}]).($numD[1]);
            }
            else if ((int) $str{$i}>1){
                $buf=($numB[(int) $str{$i}]).($numD[0]);
            }       
          break;
        case 3: case 6: case 9: case 12: case 15:
            if ((int) $str{$i}>0){
                $buf=($numB[(int) $str{$i}]).($numD[2]);
            }
          break;
        case 4: case 7: case 10: case 13:
            if (terbilang_get_valid($str,$i-2,$i)){
              if (!terbilang_get_valid($str,$i-1,$i,1,1))
                $buf=$numC[(int) $str{$i}].($numD[$pos]);
              else
                $buf=$numD[$pos];
            }           else if((int) $str{$i}>0){
              if ($pos==4)
                $buf=($numB[(int) $str{$i}]).($numD[$pos]);
              else
                $buf=($numC[(int) $str{$i}]).($numD[$pos]);
            }
          break;
      }
      return $buf;
  }
  function toTerbilang($nominal){
      $buf="";
      $str=$nominal."";
      $len=strlen($str);
      
      for ($i=0;$i<$len;$i++){
        $buf=trim($buf)." ".terbilang_get_str($i,$str,$len);
      }
      return trim($buf);
  }

// ----- >> Init
$fpdf = new thisPDF('P','mm','A4');
$fpdf->AddPage();
$fpdf->SetLeftMargin(8);

$fpdf->Ln(0);
$ln_header_y_top	= $fpdf->GetY();

{

// ----- >> Header
$fpdf->Ln(2);

//$Image = APPPATH . 'file/kstore/logo_primkokas.jpg' ; 
$fpdf->Cell( 30, 20, $fpdf->Image(APPPATH . 'file/media/logo_primkokas.jpg' , $fpdf->GetX(35), $fpdf->GetY(45)), 0, 0, 'L', false );

/*$fpdf->setFont('Arial','BI',12);
$fpdf->text(20,35,'CYBER-K NET');
$fpdf->setFont('Arial','BI',8);
$fpdf->text(20,38,'http://www.K-Cyber.net');*/

$fpdf->SetFont('Arial','B',10);
$fpdf->Cell(70,5,"",0,0,'L');
$fpdf->Cell(0,2,"PRIMER KOPERASI KARYAWAN KRAKATAU STEEL",0,0,'L');
$fpdf->Ln(5);
$fpdf->SetFont('Arial','',10);
$fpdf->Cell(87,5,"",0,0,'L');
$fpdf->Cell(0,2,"Gedung Krakatau Junction Lt. 3, Jl. KH. Yasin Neji Komp. PT KS",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(151,5,"",0,0,'L');
$fpdf->Cell(0,2,"Cilegon - Banten 42435",0,0,'L');
$fpdf->Ln(5);
$fpdf->Cell(129,5,"",0,0,'L');
$fpdf->Cell(0,2,"Telp. 0254-392 784, 372 289 ext. 117",0,0,'L');
$fpdf->Ln(5);


//$fpdf->Line(9, 42, 200-3, 42); // 197mm from each edge


// ----- >> Data Master

$fpdf->Ln(30);

// ----- >> Data Master
//setting judul laporan dan header tabel

//$fpdf->addPage();
//$fpdf->setAutoPageBreak(false);
$fpdf->setFont('Arial','B',16);
$fpdf->text(9,55,'FORM TECHNICAL SUPPORT');
$fpdf->setFont('Arial','BI',10);

$fpdf->setFont('Arial','',10);
$fpdf->Cell(40,5,"No. Reff",0,0,'L');
$fpdf->Cell(5,5,":",0,0,'L');
$fpdf->Cell(110,5,$data['kode_komplain'],'TBLR','L');
$fpdf->Ln(7);
$fpdf->Cell(40,5,"Nama",0,0,'L');
$fpdf->Cell(5,5,":",0,0,'L');
$fpdf->Cell(110,5,$data['atas_nama'],'TBLR','L');
$fpdf->Ln(7);

$fpdf->Cell(40,5,"Departemen",0,0,'L');
$fpdf->Cell(5,5,":",0,0,'L');
$fpdf->Cell(110,5,$data['nama_departemen'],'TBLR','L');
$fpdf->Ln(7);

$tgl_old1 = str_replace("/", "", $data['tgl_komplain']);

$tahun_new1 = substr($tgl_old1, 4, 4);
    $bulan_new1 = substr($tgl_old1, 2, 2);
    $hari_new1   = substr($tgl_old1, 0, 2);
    if($bulan_new1<='09'){
      $y1 = substr($bulan_new1, 1, 1);

      $hasil1 = "";
      $iromawi1 =
      array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September");
      if(array_key_exists($y1,$iromawi1)){
        $hasil1 = $iromawi1[$y1];
      }

      $tgl_new1 = $hari_new1." - ".$hasil1." - ".$tahun_new1." ";

    } else {

      $hasil1 = "";
      $iromawi1 =
      array("","","","","","","","","","","Oktober","November","Desember");
      if(array_key_exists($bulan_new1,$iromawi1)){
        $hasil1 = $iromawi1[$bulan_new1];
      }

      $tgl_new1 = $hari_new1." - ".$hasil1." - ".$tahun_new1." ";

    }

$fpdf->Cell(40,5,"Tanggal",0,0,'L');
$fpdf->Cell(5,5,":",0,0,'L');
$fpdf->Cell(50,5,$tgl_new1,'TBLR','L');


$fpdf->Cell(5,5,"",0,0,'L');
$fpdf->Cell(10,5,"Jam",0,0,'L');
$fpdf->Cell(5,5,":",0,0,'L');
$fpdf->Cell(40,5,'','TBLR','L');
$fpdf->Ln(20);


$fpdf->setFont('Arial','BU',11);
$fpdf->text(9,100,'Jenis Kebutuhan');

$data_kebutuhan = explode(',', $data['jenis_kebutuhan']);

    if($data_kebutuhan[0]!=null){
      $hardware = 'V';
    } else {
      $hardware = '';
    } 

    if($data_kebutuhan[1]!=null){
      $software = 'V';
    } else {
      $software = '';
    }

    if($data_kebutuhan[2]!=null){
      $database = 'V';
    } else {
      $database = '';
    }    

    if($data_kebutuhan[3]!=null){
      $lan = 'V';
    } else {
      $lan = '';
    }    

$fpdf->setFont('Arial','B',11);

$fpdf->Cell(9,5,"",0,0,'L');
$fpdf->Cell(5,5,$hardware,'TBLR','L');
$fpdf->Cell(45,5,'Hardware',0,0,'L');


$fpdf->Cell(5,5,$software,'TBLR','L');
$fpdf->Cell(45,5,'Software',0,0,'L');

$fpdf->Cell(5,5,$database,'TBLR','L');
$fpdf->Cell(45,5,'Database',0,0,'L');

$fpdf->Cell(5,5,$lan,'TBLR','L');
$fpdf->Cell(45,5,'LAN',0,0,'L');
$fpdf->Ln(20);

$fpdf->setFont('Arial','BU',11);
$fpdf->text(9,120,'Jenis Permintaan');

$data_permintaan = explode(',', $data['jenis_permintaan']);

    if($data_permintaan[0]!=null){
      $aplikasi = 'V';
    } else {
      $aplikasi = '';
    } 

    if($data_permintaan[1]!=null){
      $pengadaan_baru = 'V';
    } else {
      $pengadaan_baru = '';
    }

    if($data_permintaan[2]!=null){
      $technical_support = 'V';
    } else {
      $technical_support = '';
    }    


$fpdf->setFont('Arial','',10);    
$fpdf->Cell(9,5,"",0,0,'L');
$fpdf->Cell(5,5,$aplikasi,'TBLR','L');
$fpdf->Cell(45,5,'Aplikasi',0,0,'L');


$fpdf->Cell(5,5,$pengadaan_baru,'TBLR','L');
$fpdf->Cell(30,5,'Penambahan / Pengadaan Baru',0,0,'L');
$fpdf->Cell(30,5,'',0,0,'L');


$fpdf->Cell(5,5,$technical_support,'TBLR','L');
$fpdf->Cell(45,5,'Technical Support / Trouble Shooting',0,0,'L');

$tgl_old1 = str_replace("/", "", $data['tgl_komplain']);

$tahun_new1 = substr($tgl_old1, 4, 4);
    $bulan_new1 = substr($tgl_old1, 2, 2);
    $hari_new1   = substr($tgl_old1, 0, 2);
    if($bulan_new1<='09'){
      $y1 = substr($bulan_new1, 1, 1);

      $hasil1 = "";
      $iromawi1 =
      array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September");
      if(array_key_exists($y1,$iromawi1)){
        $hasil1 = $iromawi1[$y1];
      }

      $tgl_new1 = $hari_new1." - ".$hasil1." - ".$tahun_new1." ";

    } else {

      $hasil1 = "";
      $iromawi1 =
      array("","","","","","","","","","","Oktober","November","Desember");
      if(array_key_exists($bulan_new1,$iromawi1)){
        $hasil1 = $iromawi1[$bulan_new1];
      }

      $tgl_new1 = $hari_new1." - ".$hasil1." - ".$tahun_new1." ";

    }

$fpdf->Ln(20);

$fpdf->setFont('Arial','B',11);
$fpdf->text(9,142,'Uraian permohonan atau masalah yang terjadi :');

$fpdf->setFont('Arial','',11);
$fpdf->Cell(1,5,"",0,0,'L');
$fpdf->Cell(180,35,$data['komplain'],'TBLR','L');
$fpdf->Ln(38);

$fpdf->setFont('Arial','B',11);
$fpdf->text(9,186,'Solusi :');

$fpdf->setFont('Arial','',11);
$fpdf->Ln(7);
$fpdf->Cell(1,5,"",0,0,'L');
$fpdf->Cell(180,35,$data['keterangan'],'TBLR','L');
$fpdf->Ln(38);

$fpdf->setFont('Arial','B',11);
$tgl_old2 = str_replace("/", "",$data['tanggal_selesai']);

//var_dump($tgl_old2);

$tahun_new2 = substr($tgl_old2, 4, 4);
    $bulan_new2 = substr($tgl_old2, 2, 2);
    $hari_new2   = substr($tgl_old2, 0, 2);
    if($bulan_new2<='09'){
      $y1 = substr($bulan_new2, 1, 1);

      $hasil2 = "";
      $iromawi2 =
      array("","Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September");
      if(array_key_exists($y1,$iromawi2)){
        $hasil2 = $iromawi1[$y1];
      }

      $tgl_new2 = $hari_new2." - ".$hasil2." - ".$tahun_new2." ";

    } else {

      $hasil2 = "";
      $iromawi2 =
      array("","","","","","","","","","","Oktober","November","Desember");
      if(array_key_exists($bulan_new2,$iromawi2)){
        $hasil2 = $iromawi1[$bulan_new2];
      }

      $tgl_new2 = $hari_new2." - ".$hasil2." - ".$tahun_new2." ";

    }

$fpdf->setFont('Arial','B',10);
$fpdf->Cell(25,5,"Tanggal       :",0,0,'L');
$fpdf->Cell(50,7,'','TBLR','L');
$fpdf->setFont('Arial','',10);
$fpdf->Ln(15);


$fpdf->setFont('Arial','B',11);
$fpdf->Cell(1,5,"",0,0,'L');
$fpdf->Cell(50,35,'','TBLR','L');
$fpdf->text(25,245,'Pemohon');
$fpdf->text(13,273,'(                                    )');

$fpdf->Cell(15,5,"",0,0,'L');
$fpdf->Cell(50,35,'','TBLR','L');
$fpdf->text(84,245,'Atasan Pemohon');
$fpdf->text(79,273,'(                                    )');

$fpdf->Cell(15,5,"",0,0,'L');
$fpdf->Cell(50,35,'','TBLR','L');
$fpdf->text(145,245,'IT Dept. Management');
$fpdf->text(144,273,'(                                    )');

}


$date = date('d-M-y');

echo $fpdf->Output('Laporan Data Kontrol Air'." "."$date"." ".'.pdf','I');
exit();
?>